{% extends 'index.html' %}
{% load student_tags %}
{% block custome_css %}
    <link rel="stylesheet" href="/static/plugin/dropzone/dropzone.min.css">
    <style>
        .dropzone {
            border: 2px dashed #0087F7;
            border-radius: 5px;
            background: white;
        }

        .dropzone .dz-message {
            font-weight: 400;
        }

        .dropzone .dz-message .note {
            font-size: 0.8em;
            font-weight: 200;
            display: block;
            margin-top: 1.4rem;
        }
    </style>
{% endblock %}
{% block pg-content %}
    作业详情
    <div class="panel panel-info">
        <div class="panel-heading">{{ studyrecord_obj.student.enrolled_class }} | 节次{{ studyrecord_obj.course_record.day_num }}</div>
        <div class="panel-body">
            <h4>作业标题: {{ studyrecord_obj.course_record.homework_title }}</h4>
            <h4>作业详情: <pre>{{ studyrecord_obj.course_record.homework_content }}</pre></h4>
            <h4>老师评语: {{ studyrecord_obj.memo }}</h4>
            <h4>成绩: {{ studyrecord_obj.score }}</h4>
            <h4>已上传作业:</h4>
            <h4 id="homework_list">
                {% for file in homework_list %}
                    <li>{{ file }}<a class="delete_file" href="{% url 'delete_homework' studyrecord_obj.id file%}">&lt; 点击删除</a></li>
                {% endfor %}
            </h4>
            <hr/>
            <form id="fileDropzone" action="{{ request.path_info }}" class="dropzone" method="post">
                {% csrf_token %}
                <div class="dz-message">将作业打包成zip格式后提交，只能提交一个压缩包</div>
            </form>
        </div>
    </div>
    <form method="post">
        {% csrf_token %}
        <input type="submit" class="btn btn-success pull-right" value="确定">
    </form>
{% endblock %}
{% block custome_js %}
    <script src="/static/plugin/dropzone/dropzone.min.js"></script>
    <script>
        $(function () {
            Dropzone.autoDiscover = false;

            $("#fileDropzone").dropzone({
                paramName: "file", // The name that will be used to transfer the file
                maxFilesize: 5, // MB
                maxFiles: 1,
                uploadMultiple: true,    //一次性上传多个文件
                acceptedFiles: '.zip',    // 只允许上传zip
                addRemoveLinks: true,
                dictInvalidFileType: '不支持该文件类型',
                dictRemoveFile: '点击删除该文件',
                accept: function(file, done) {
                    done();
                },
                success: function (file,data) {
                    res = $.parseJSON(data);
                    if(!res['status']){
                        alert(res['errors']);
                    }else{
                        $.each(res['message'],function(index,value){
                            var li_ele = document.createElement('li');
                            $(li_ele).text(value);
                            $(li_ele).html(value);
                            $('#homework_list').empty();
                            $('#homework_list').append(li_ele);
                });
                    }
                },
                init: function () {
                    this.on('removedfile', function (file) {
                        $.get('/student/delete_homework/{{ studyrecord_obj.id }}/'+file.name);
                        $('#homework_list').empty();

                    })
                }
            });

            $('#homework_list').delegate('.delete_file','click',function () {
                $.get($(this).attr('href'), function(data){});
                $(this).parent().remove();
                return false;
            });
        });
    </script>

{% endblock %}